package com.wxt.blog.service;

import com.wxt.blog.dao.CommentDao;
import com.wxt.blog.entity.Comment;
import com.wxt.blog.util.MyBatisUtil;

import java.util.ArrayList;
import java.util.List;

public class CommentService {

    public void addComment(Comment comment) {
        try {
            CommentDao dao = MyBatisUtil.getMapper(CommentDao.class);
            dao.insert(comment);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("添加评论失败");
        }
    }

    public List<Comment> getCommentsByBlogId(int blogId) {
        try {
            CommentDao dao = MyBatisUtil.getMapper(CommentDao.class);

            return dao.findByBlogId(blogId);
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
}